<%@ page import="java.sql.Statement" import="java.sql.ResultSet" import="java.sql.Connection" %>
<%@page import="connection.DBConnection"%>
<%@page import="java.util.*" %>
<%@page import="java.text.SimpleDateFormat" %>
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title> Journal Voucher Report</title>
</head>
<body>
<h2 align="center"> Journal Voucher Report</h2>
<form name="fr15" method="post">

  <%
        String exportToExcel = request.getParameter("exportToExcel");
        if (exportToExcel != null && exportToExcel.toString().equalsIgnoreCase("YES")) 
        {
            response.setContentType("application/vnd.ms-excel");
            response.setHeader("Content-Disposition", "inline; filename=" + "JournalVoucherReport.xls");
 
        }
    %>

<table border=2 align="center"> 

<tr>
		<th> Voucher Entry Number </th>
		<th> Date </th>
		<th> Account Debited </th>
		<th> Amount </th>
		<th> Account Credited </th>
		<th> Amount </th>
		<th> Narration </th>
			 
</tr>

		<%  DBConnection dbc=new DBConnection();
			Connection con=dbc.getNewConnection();
			Statement st = null;
			ResultSet rs = null;
			
			double amount4=0.0,amount6=0.0;
			double jv4=0.0,jv6=0.0;
			try
			{
			   st=con.createStatement() ;
       		   rs=st.executeQuery("select * from journalVoucher2 where status=1"); %>
	        	
       		 <%  while(rs.next()){ %>
<tr>
            		<td><%= rs.getString(1)%></td>

            		<% String jvdate= rs.getString(2); 
           	    		 SimpleDateFormat fromsql = new SimpleDateFormat("yyyy-MM-dd");
        				 SimpleDateFormat formatter = new SimpleDateFormat("dd-MM-yyyy");
        		 		 String newdate =formatter.format(fromsql.parse(jvdate));
            		%>
            		<td><%=newdate %></td>
            		
            		<td><%= rs.getString(3)%></td>
            		
            		<% jv4= rs.getDouble(4); %>
            		<td><%=jv4 %></td>
            		<td><%= rs.getString(5)%></td>
            		
            		<% jv6= rs.getDouble(6); %>
            		<td><%=jv6%></td>
            		<td><%= rs.getString(7)%></td>
            		
</tr>
        		<% 
        			amount4=amount4+jv4;
        			amount6=amount6+jv6;
        			} %>
  
	 		<% }
			catch(Exception e){} %>
			
<tr>
	<td> <b> Total </b></td>
	<td> </td>
	<td> </td>
	<td> <%=amount4 %> </td>
	<td> </td>
	<td> <%=amount6 %> </td>
	<td> </td>
</tr>
<!-- 
<tr>
		<td> ${CMR.jname} </td> 
		<td> ${CMR.date} </td>
		<td> ${CMR.jaccdeb} </td>
		<td> ${CMR.jamount1} </td>
		<td> ${CMR.jaccred} </td>
		<td> ${CMR.jamount2} </td>
		<td> ${CMR.jnar} </td>
		
</tr>
-->
</table><br><br> 
	&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;

    <%
        if (exportToExcel == null) {
    %>
    <a href="JournalVoucherReport.jsp?exportToExcel=YES">Export to Excel</a>
    <%
        }
    %>
</form>

<br><br> 
	&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;

<form name="delete_form" action="JournalVoucherDeleteServlet">
<input type="text" name="delete"> 
<input type="submit" value="Delete Voucher">

<br><br> 
	&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;

<a href="http://localhost:8081/BOA_Web/DeletedJournalVouchers.jsp">Deleted Journal Vouchers</a>

<center><input type="button" value="Print this page" onClick="window.print()"></center>
</form>


</body>
</html>